<?php
require 'config.php';
require CAMINHO_SERVIDOR . 'funcoes.php';
require 'login.class.php';
$login = new Login();
if ($login->verificar()) {
    $query = "SELECT * FROM tb_campeonato ORDER BY descricao";
    $campeonatos = $login->executaQueryAll($query);
    $query = "SELECT * FROM tb_usuario ORDER BY nome";
    $usuarios = $login->executaQueryAll($query);
    ?>
    <html>
        <head>
            <title>Jogo</title>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width">
            <link rel="stylesheet" type="text/css" href="<?php echo URL; ?>bootstrap/css/bootstrap.css">
            <link rel="stylesheet" type="text/css" href="<?php echo URL; ?>css/classes.css">
            <style type="text/css">
                h2{
                    color: #888888;
                    font-size: 18px;
                }
            </style>
        </head>
        <body>
            <div class="container-fluid">
                <div class="col-md-10 col-md-offset-1">
                    <div class="marginBotton10percent">
                        <p>Bem vindo, <?php echo $LoginUsuario ?>&nbsp;&nbsp;&nbsp;&nbsp;<a href="logout.php" >Sair</a></p>
                        <input id="id_jogo" type="hidden" value="<?php echo $_GET["id_jogo"] ?>" name="id_jogo"/>
                    </div>
                    <div class="col-md-4">
                        <div class="panel panel-primary">
                            <div class="panel-heading">
                                <h3 class="panel-title text-center">Jogo</h3>
                            </div>
                            <div class="panel-body text-center">
                                <div class="form-group">
                                    <a class="btn btn-info" style="width: 170px" href="<?php echo URL; ?>cadTimes.php" >Cadastrar Times</a>
                                </div>
                                <div class="form-group">
                                    <a class="btn btn-info" style="width: 170px" href="<?php echo URL; ?>cadJogos.php" >Cadastrar Jogo</a>
                                </div>
                                <div class="form-group">
                                    <a class="btn btn-info" style="width: 170px" href="<?php echo URL; ?>campeonato/index.php">Cadastrar Campeonato</a>
                                </div>
                                <div class="form-group">
                                    <a class="btn btn-success" style="width: 170px" href="<?php echo URL; ?>campeonato2/campeonato1.php">Novo Campeonato</a>
                                </div>
                                <div class="form-group">
                                    <a class="btn btn-info" style="width: 170px" href="<?php echo URL; ?>listaJogos.php">Listar Jogos</a>
                                </div>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-4">
                        <div class="panel panel-primary">
                            <div class="panel-heading">
                                <h3 class="panel-title text-center">Ranking</h3>
                            </div>
                            <div class="panel-body">
                                <form action="<?php echo URL ?>ranking.php" method="POST">
                                    <label>Campeonato:</label>
                                    <select class="form-control" name="id_campeonato" id="id_campeonato">
                                        <?php
                                        foreach ($campeonatos as $cam) {
                                            if ($cam["id_campeonato"] == $dadosJogo["id_campeonato"]) {
                                                $selected = "selected='selected'";
                                            } else {
                                                $selected = "";
                                            }
                                            ?>
                                            <option <?php echo $selected ?>  value="<?php echo $cam["id_campeonato"]; ?>"><?php echo $cam["descricao"]; ?></option>
                                        <?php } ?>
                                    </select>
                                    <div class="marginTop30px">
                                        <button class="btn btn-info offset0" type="submit" >Ir ao Ranking</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>

                    <div class="col-md-4">
                        <div class="panel panel-primary">
                            <div class="panel-heading">
                                <h3 class="panel-title text-center">Apostar</h3>
                            </div>
                            <div class="panel-body">
                                <form action="<?php echo URL ?>listaApostas.php" method="post">
                                    <label>Usuário:</label>
                                    <select class="form-control" name="id_usuario" id="id_usuario">
                                        <?php
                                        foreach ($usuarios as $usu) {
                                            ?>
                                            <option value="<?php echo $usu["id_usuario"]; ?>"><?php echo $usu["nome"]; ?></option>
                                        <?php } ?>
                                    </select>
                                    <div class="marginTop30px">
                                        <button class="btn btn-info offset0" type="submit" >Ir para Apostas</button>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </body>
    </html>
<?php } else { ?>
    <html>
        <head>
            <title>Login</title>
            <meta charset="UTF-8">
            <meta name="viewport" content="width=device-width">
            <link rel="stylesheet" type="text/css" href="bootstrap/css/bootstrap.css">
            <link rel="stylesheet" type="text/css" href="bootstrap/css/classes.css">
        </head>
        <body>
            <div class="container">
                <div class="col-md-4 col-md-offset-4">
                    <div class="padding20px margin30px bordaDecorada" style="background-color: #fafafa;">
                        <form class="form-signin" role="form" action="verificar.php"  method="post">
                            <div  style="text-align: center">
                                <img width="75px" height="75px" src="imagens/cadeado.png"/>
                            </div>
                            <input type="text" name="login" class="form-control" placeholder="Login" required autofocus><br />
                            <input type="password" name="senha" class="form-control" placeholder="Senha" required>
                            <br />
                            <input class="  btn btn-lg btn-primary btn-block" type="submit" value="Entrar">
                        </form>
                    </div>
                </div>
            </div>

            <?php
            if (isset($_GET["msg"])) {
                if ($_GET["msg"] == 1) {
                    ?>
                    <div class="col-md-4 col-md-offset-4">
                        <div class="alert alert-danger text-center">Login e/ou Senha inválida!</div>
                    </div>
                <?php
                }
            }
            ?>
        </body>
    </html>
<?php } ?>